package cn.yi.medicalsys.dao.impl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import cn.yi.medicalsys.dao.UserDao;
import cn.yi.medicalsys.pojo.User;
import cn.yi.medicalsys.utils.BaseDao;

public class UserDaoImpl extends BaseDao implements UserDao {

	@Override
	public User findUserByNo(Integer userno) throws Exception {
		User user=null;
		String preparedSql="SELECT uname,userSex,userEmail FROM `user` WHERE uid=?";
		Object[] params={userno};
		ResultSet rs=super.executeQuery(preparedSql, params);
		while(rs.next()){
			user=new User();
			user.setuName(rs.getString("uname"));
			user.setUserSex(rs.getString("userSex"));
			user.setUserEmail(rs.getString("userEmail"));
		}
		return user;
	}

	/**
	 * 根据用户编号uid来查询用户姓名和性别
	 */
	@Override
	public List<User> findUserByUid(Integer uid) throws Exception {
		List<User> list=new ArrayList<User>();
		User user = null;
		String sql = "SELECT uid,`uname`,userSex,userAge,userPhone,userAddress,userCodeId,regDate,userState,userName,userPass,userEmail FROM `user` WHERE `uid`=?";
		Object[] params = { uid };
		ResultSet rs = super.executeQuery(sql, params);
		if (rs.next()) {
			user = new User();
			user.setuId(rs.getInt("uid"));
			user.setUserName(rs.getString("uname"));
			user.setUserSex(rs.getString("userSex"));
			list.add(user);
		}
		super.closeResource(rs);
		return list;
	}
}
